const {
  MemberModel
} = require('../../../utils/member-model.js');
var memberModel = new MemberModel();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardList: [], //卡列表
  },
  onLoad: function (options) {},
  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function () {
    this.getCardList(); //会员卡列表
  },
  /**
   * 会员卡列表
   */
  getCardList: function () {
    memberModel.userCardList({
      merchantId: wx.getStorageSync('merchantId')
    }).then(data => {
      if (data && data.length > 0) {
        var dataList = [];
        for (var i = 0; i < data.length; i++) {
          var list = {};
          list.memberLevelName = data[i].memberLevelName || '';
          list.memberLevel = data[i].memberLevel ? 'V' + data[i].memberLevel : 'V0';
          list.cardNo = data[i].cardNo.replace(/(.{4})/g, '$1 ') || '';
          list.rightsType = data[i].rightsType;
          dataList.push(list);
        }
        this.setData({
          cardList: dataList
        });
      }
    }).catch(err => {
      wx.showToast({
        title: `${err.error}`,
        icon: 'none',
        duration: 2000
      })
    })
  },

  //跳转到绑卡页面
  goAddCard: function () {
    wx.navigateTo({
      url: '/pages/memberCenter/addCard/index'
    })
  }

})